<?php
class scaffolding
    {
    public $modul;
    public $modulModus = true;

    public $paging = true;
    public $search = false;
    public $searchIndex = false;

    public $newItem = true;
    public $editItem = true;
    public $deleteItem = true;
    public $excelExport = true;

    public $searchForm = true;

    public $table;
    public $tableArray;
    public $categoryTable = "";
    // public $tableOrginal;
    public $titleReport = "Daten Auflistung";
    public $titleForm = "Daten Erfassung";

    public $overwrite = true;
    public $parentUrl = "";
    public $template = "";
    public $preUrl = "";
    public $usergroup = 10;

    public $tableClass = "snapol_table";

    public $tableField = "";
    public $tableFieldType = array();
    public $tableFieldTitle = "";
    public $formField = array();
    public $formFieldCaption = array();
    
    public $formFieldType = array();
    public $formFieldRequired = array();

    public $joinField = array();

    public $tableOrderby = "";

    public $pageTitle = "";


    //private $formRedirect = "";

    private $html = "";

    private $htmlForm = "";
    private $htmlReport = "";

    public $formUrl;
    public $tableUrl;
    public $formRedirect = "";

    public $formClass = "snapol_form";

    public $errorMessageClass = "";

    function __construct()
        {
        global $rootDir;
        global $webDir;

        //require_once ("$rootDir$webDir/snapol/api/simplehtmldom/simple_html_dom.php");
        }


    //$modul, $table
    function createModul()
        {
        $this->table=strtolower($this->table);

        /*     if ($this->modulModus)
             modul::createModul($this->modul, false);      */

        if ($this->tableField == "")
            {
            $tableField=db::getTableFieldArray($this->table);

            $this->tableField=array();

            for ($n=0; $n < sizeof($tableField); $n++)
                {
                $tmp = strtolower($tableField[$n]);

                if ($tmp == "id")
                    $tmp="";

                if ($tmp == "id2")
                    $tmp="";

                if ($tmp !== "")
                    $this->tableField[]=$tmp;


                // erstes Feld als Order By
                if ($this->tableOrderby == "")
                    $this->tableOrderby=$tmp;
                }
            //$this->tableField

            }
        else
            {
            $this->tableField=general::stringToArray($this->tableField, true);
            }


        /*           echo "ORDERBY ".$this->tableOrderby;
                   
               //print_r($this->tableField);
       
               $this->urlReport=modul::createModulPage($this->modul, $this->titleReport);
       
               if ($this->newItem)
                   {
                   $this->urlForm=modul::createModulPage($this->modul, $this->titleForm, "", "", false);
                   $this->createForm();
                   $urlForm=modul::createModulPage($this->modul, $this->titleForm, $this->htmlForm, "", "", false);
       
                   $this->addNewItem();
                   }
       
               $this->createTable();
               $urlReport=modul::createModulPage($this->modul, $this->titleReport, $this->htmlReport);
       
       
               // echo $this->htmlReport; 
       
       
               //     $modul = "second";
               //$table = "inhalt";
       
               /*  $titleReport = "Daten Auflistung $table";
                 $titleForm = "Daten Erfassung $table";
                 
                 
                 
                 //modul::createModul($modul);
                 $urlReport = modul::createModulPage($modul, $titleReport);
                 $urlForm = modul::createModulPage($modul, $titleForm);
                 
                 $htmlForm = scaffolding::createForm($table, $urlReport);
                 $htmlReport = scaffolding::createTable($table, $urlForm);        
                
                 $htmlReport = scaffolding::addNewItemButton($urlForm).$htmlReport;
                
                 
                 $urlReport = modul::createModulPage($modul, $titleReport, $htmlReport);
                 $urlForm = modul::createModulPage($modul, $titleForm, $htmlForm);*/


        // return $this->html;

        }

    function createPage()
        {


        /* if ($this->newItem) {
         
           $htmlForm = $this->createForm();   //$formTable, $formField, "", $fieldType, $redirect, $formSearchindex);
        
           //echo $htmlForm;
           
           //echo "SELECT _template FROM page WHERE id={$this->pageId}";
           //$templateId = db::getValue("SELECT __template FROM page WHERE id={$this->pageId}");
           //$template = db::getValue("SELECT template FROM _template WHERE id=$templateId");
           
           
         /*  
           $formUrl = page::createPage("Daten Erfassung $table", $htmlForm, $this->pageUrl, false, 0, 30, true, "", $template);
           $tmp = $scaffolding->addNewItem($formUrl);        
         
         }
         
         $htmlTableSeearch = "";
         if ($tableSearch) {
               $htmlTableSeearch = component::getCom("form_search");       
         }
            */


        //  $htmlForm = $htmlForm.$this->pageUrl;


        //$scaffolding->createModul();

        //->createscaffolding->createTable2($table, $tableField, $editItem, $deleteItem, $formUrl, $tableSearch);

        //$tmp = $htmlTableSeearch.$tmp;

        //$scaffolding->createForm();

        if ($this->pageTitle == "")
            {
            $this->pageTitle=db::getValue("SELECT table_title FROM _table WHERE `table`= '$this->table'");
            }

        $this->tableArray=general::stringToArray($this->table);

        $this->parentUrl="/admin/verwaltung";
        $this->template="admin.html";
        $this->preUrl="/admin/modul/" . strtolower($this->tableArray[0]);

        if (!db::tableExist($this->tableArray[0]))
            {
            echo "<p>Error: Tabelle {$this->tableArray[0]} existiert nicht.</p>";
            //exit;
            }


        // Seite erstellen, damit die Url bekannt ist
        $this->tableUrl=
            page::createPage($this->pageTitle, "", $this->parentUrl, true, $this->usergroup, 50, $this->overwrite, "",
                $this->template, true, $this->preUrl); // $htmlForm, $this->pageUrl, false, 0, 30, true, "", $template);

        $htmlTable="";

        // Erstellung des Formular
        if ($this->newItem)
            {
            $htmlForm=$this->createForm(); //$formTable, $formField, "", $fieldType, $redirect, $formSearchindex);

            //echo $htmlForm;

            //echo "SELECT _template FROM page WHERE id={$this->pageId}";
            //$templateId = db::getValue("SELECT __template FROM page WHERE id={$this->pageId}");
            //$template = db::getValue("SELECT template FROM _template WHERE id=$templateId");

            $this->formUrl=page::createPage("Daten Erfassung {$this->pageTitle}", $htmlForm, $this->tableUrl, false,
                $this->usergroup, 50, $this->overwrite, "", $this->template, true, $this->preUrl);
            $htmlTable=$this->addNewItem($this->formUrl);
            }

        //$this->tableField=array();


        //$this->categoryTable = "usergroup";

        $htmlTable=$htmlTable . $this->createCategory() . $this->createTable();
        $formUrl=page::createPage($this->pageTitle, $htmlTable, $this->parentUrl, true, $this->usergroup, 50,
            $this->overwrite, "", $this->template, true,
            $this->preUrl); // $htmlForm, $this->pageUrl, false, 0, 30, true, "", $template);

        return $formUrl;
        }

    function createForm() //$table = "", $field = "", $fieldTitle = "", $fieldType = "", $redirect = "", $searchindex = false)
        {
        //$class="snapol_form";

        //$replaceCom = new replace_com();

        $html='<form class="' . $this->formClass . '" action="' . $this->formRedirect . '" com="save_form" table="'
            . $this->table . '">';


        /*$e->table     = $this->table;

           $e->com_action="save_form";

           if ($this->searchIndex)
               {
               $e->searchindex="true";
               }

           $e->redirect=$this->formRedirect; // $redirect; // "";   //  $this->urlReport; */

        if ($this->tableField == "")
            {
            }

        /*if ($this->formField == "")
            {
            //$field=db::getTableFieldArray($this->table);
            $field=db::getSnapolTableFieldArray($this->table);

            //print_r($field);

            }
        else
            {
            $field=general::stringToArray($this->formField);
            }          */


        //print_r($field);


        //$field = general::stringToArray($field);
        //$fieldType = general::stringToArray($fieldType);

        $counter=0;

        //foreach ($field as $value)
        foreach ($this->formField as $field)
            {
            //$com  = db::getSnapolTableFieldType($this->table, $value);
            //$title=db::getSnapolTableFieldName($this->table, $value);


            //$comData = $data=data::getTableLine("_table_field,_table", "`table`='{$this->table}' AND field='$value'");

            if ($this->formFieldType[$field] == "")
                {
                $this->formFieldType[$field]="text";
                }

            $com=strtolower($this->formFieldType[$field]);

            $title=$field;
            $required=false;


            //$com = $fieldType[$counter];
            //$com = "text";


            //echo "com $com";
            //echo "title $title";

            $text="<p>Fehler: Kein component gefunden. com=$com, title=$title</p>";

            if ($com == "resize_image")
                $text="";

            if ($title == "_url")
                $text="";

            if ($title == "_date")
                $text="";

            if ($title == "_time")
                $text="";

            if ($title == "_datetime")
                $text="";


            //   or ($com == "required_text") or ($com == "required_email") or ($com == "url")    or ($com == "number")
            if (($com == "text") or ($com == "time"))
                {
                //$text=component::getCom("input_text");
                /*$comData=component::getCom("input_text");
                $text=$comData['body'];
                $text=dom::setAttribute("input", "name", $field, $text);
                $text=dom::setAttribute("input", "id", $field, $text);*/

                // falls required_text, Fehlermeldung einbinden
                $check="";

                if ($this->formFieldRequired[$field] == "true")
                    {
                    //$text=dom::setAttribute("input", "check_content", "true", $text);
                    $check='check_content="true"';
                    }

                $text='<p><label></label>
  <input type="text" name="' . $field . '" id="' . $field . '" ' . $check . ' /></p>';
                }

            if ($com == "email")
                {


                // falls required_text, Fehlermeldung einbinden
                $check="";

                if ($this->formFieldRequired[$field] == "true")
                    {
                    //$text=dom::setAttribute("input", "check_content", "true", $text);
                    $check='check_email="true"';
                    }

                $text='<p><label></label>
  <input type="text" name="' . $field . '" id="' . $field . '" ' . $check . ' /></p>';
                }

            if ($com == "url")
                {


                // falls required_text, Fehlermeldung einbinden
                $check="";

                if ($this->formFieldRequired[$field] == "true")
                    {
                    //$text=dom::setAttribute("input", "check_content", "true", $text);
                    $check='check_url="true"';
                    }

                $text='<p><label></label>
  <input type="text" name="' . $field . '" id="' . $field . '" ' . $check . ' /></p>';
                }

            if ($com == "number")
                {


                // falls required_text, Fehlermeldung einbinden
                $check="";

                if ($this->formFieldRequired[$field] == "true")
                    {
                    //$text=dom::setAttribute("input", "check_content", "true", $text);
                    $check='check_number="true"';
                    }

                $text='<p><label></label>
  <input type="text" name="' . $field . '" id="' . $field . '" ' . $check . ' /></p>';
                }


            /*  $text=component::getCom($dataForm->data['com']);
              $text=dom::setAttribute("input", "name", $dataForm->data['field'], $text);
              $text=dom::setAttribute("input", "id", $dataForm->data['field'], $text);
  
              $text=dom::replaceInnerHtml("label", $dataForm->data['field'], $text);  */


            // falls Text Area
            if ($com == "long_text")
                {


                // falls required_text, Fehlermeldung einbinden
                $check="";

                if ($this->formFieldRequired[$field] == "true")
                    {
                    //$text=dom::setAttribute("textarea", "check_content", "true", $text);
                    $check='check_content="true"';
                    }

                $text='<p><label></label>
  <textarea name="' . $field . '" id="' . $field . '" ' . $check . ' cols="60" rows="10"></textarea></p>';
                }


            // falls Text Area
            if ($com == "html")
                {
                $check="";

                if ($this->formFieldRequired[$field] == "true")
                    {
                    $check='check_content="true"';
                    }

                $text='<p><label></label>
  <textarea com="ck_editor" name="' . $field . '" id="' . $field . '" ' . $check
                    . ' cols="60" rows="10"></textarea></p>';
                }


            // falls Datum
            if ($com == "date")
                {


                // falls required_text, Fehlermeldung einbinden
                $check="";

                if ($this->formFieldRequired[$field] == "true")
                    {
                    $check='check_content="true"';
                    }

                $text='<p><label></label>
  <input type="text" com="date_picker" name="' . $field . '" id="' . $field . '" ' . $check . ' /></p>';
                }


            // falls Checkbox
            if ($com == "checkbox")
                {
                /* $comData=component::getCom("input_checkbox");
                 $text=$comData['body'];
                 $text=dom::setAttribute("input", "name", $field, $text);
                 $text=dom::setAttribute("input", "id", $field, $text);
                 $text=dom::setAttribute("label", "for", $field, $text);*/

                $text='<p>
  <label><input type="checkbox" name="' . $field . '" id="' . $field . '"  />' . $field . '"></label></p>';
                }


            // falls Image File
            if ($com == "image")
                {
                $text='<p><img src="[form_view:' . $field . ':100]" /></p><p><label></label>
  <input type="file"  name="' . $field . '" id="' . $field . '" /></p>';
                }


            // falls File
            if ($com == "file")
                {
                $text='<p><label></label>
  <input type="file"  name="' . $field . '" id="' . $field . '" /></p>';
                ;
                }


            // falls Select
            if ($com == "join")
                {
                //$comData=component::getCom("select");

                //$text=$comData['body'];
                $selectTable=$field;
                $selectTable=substr($selectTable, 1);

                /* $text=dom::setAttribute("select", "name", $field, $text);
                 $text=dom::setAttribute("select", "id", $field, $text);
 
                 $text=dom::setAttribute("select", "com", "data", $text);
                 $text=dom::setAttribute("select", "table", $selectTable, $text);
                 $text=dom::setAttribute("option", "value", "[id]", $text);
                 $text=dom::replaceInnerHtml("option", "[$selectTable]", $text);    */

                //$joinTable=substr($value, 1);
                $joinTable=substr($field, 1);


                //echo "join field:".$this->joinField."-----";

                //print_r($this->joinField);

                $optionField="";
                //if ($this->joinField !== "") {

                foreach (general::stringToArray($this->joinField[$field]) as $joinFieldItem)
                    {
                    $optionField = $optionField . "[$joinFieldItem] ";

                    echo "item=$joinFieldItem***";
                    }


                // falls nichts definiert wurde
                if ($optionField === "")
                    {
                    $optionField="[$selectTable]";
                    }

                $text='<label></label>
    <select name="' . $field . '" id="' . $field . '" com="data" table="' . $selectTable . '" orderby="" limit="">
        <option value="[id]">' . $optionField . '</option>
    </select>';
                }


            // falls required_text, Fehlermeldung einbinden
            if ($this->formFieldRequired[$field] == "true")
                {
                $title=$title . " <b>[error:$field]</b>";
                }

            $text=dom::replaceInnerHtml("label", $title, $text);

            //print_r($comData);
            //exit;

            //if ($com == "required_text")
            /* wieder aktivieren     if ($com == "text") // and ($comData['required'] == 1))
                     {
     
                     //$text = dom::replaceInnerHtml("label", $dataForm->data['field']." [error:{$dataForm->data['field']}]",$text);
                     $text=dom::replaceInnerHtml("label",
                                                 $title . ' <span com="error" field="' . $value
                                                     . '" error_message="uups, es gab einen Fehler!!!">Error Message</span>',
                                                 $text);
                     $text=dom::setAttribute("input", "check_content", "on", $text);
                     $text=dom::setAttribute("input", "check_content_error_message", "uups, hier gabs einen fehler.", $text);
                     }
     
                 // falls required_email
                 //if ($com == "required_email")
                 if (($com == "email") and ($comData['required'] == 1))    
                     {
                     $text=dom::replaceInnerHtml("label",
                                                 $title . ' <span com="error" field="' . $value
                                                     . '" error_message="Keine gÃƒÂ¼ltige eMail Adresse.">Error Message</span>',
                                                 $text);
                     $text=dom::setAttribute("input", "check_email", "on", $text);
                     }  */


            // Set Focus setzen (beim ersten Element)
            if ($counter == 0)
                {


//wieder aktivieren problem mit php und html header!!!!    $text=dom::setAttribute("input", "com", "set_focus", $text);
                }


            //echo $text;

            $html=$html . $text;

            $counter++;
            //   } while ($dataForm->nextRow());
            }

        //$text=component::getCom("input_submit");
        //$text = $replaceCom->getComData("input_submit");
        //$comData = $replaceCom->getComData("input_submit");

        // Submit Button anfÃ¼gen
        //$comData=component::getCom("input_submit");

        //$text=$comData['body'];

        $text='<p><label></label>  
  <input type="submit" name="" value="Speichern" /></p>';

        $html=$html . $text;

        $html=$html . "</form>";

        /* $dom =str_get_html($html);
 
         foreach ($dom->find('form')as $e)
             {
             // [header] --> zum EinfÃƒÂ¼gen von Header Informationen, die direkt aus dem File stammen
             //$e->innertext = $e->innertext.'<div com="content_header" field=""></div>[header]';
             //$e->table     = $this->tableArray[0]; // $this->table;
             $e->table     = $this->table;
 
             $e->com_action="save_form";
 
             if ($this->searchIndex)
                 {
                 $e->searchindex="true";
                 }
 
             $e->redirect=$this->formRedirect; // $redirect; // "";   //  $this->urlReport;
             }
 
         $html=$dom->save();
         $dom->clear();
         unset ($dom); */

        $this->htmlForm=$this->htmlForm . $html;

        return $html;
        }

    function addHtml($html)
        {
        $this->html=$this->html . $html;
        }

    function createFormOld()
        {
        $class="snapol_form";

        $html='<form class="' . $class . '">';

        $dataForm=new data("_table_field, _table, _table_field_type", "`table`='$this->table' AND type<>'resize_image'",
            "item_order");

        $counter=0;

        do
            {
            $text=component::getCom($dataForm->data['com']);
            $text=dom::setAttribute("input", "name", $dataForm->data['field'], $text);
            $text=dom::setAttribute("input", "id", $dataForm->data['field'], $text);

            $text=dom::replaceInnerHtml("label", $dataForm->data['field'], $text);


            // falls Text Area
            if ($dataForm->data['type'] == "long_text")
                {
                $text=dom::setAttribute("textarea", "name", $dataForm->data['field'], $text);
                $text=dom::setAttribute("textarea", "id", $dataForm->data['field'], $text);
                }


            // falls Select
            if ($dataForm->data['type'] == "join")
                {
                $selectTable=$dataForm->data['field'];
                $selectTable=substr($selectTable, 1);

                $text=dom::setAttribute("select", "name", $dataForm->data['field'], $text);
                $text=dom::setAttribute("select", "id", $dataForm->data['field'], $text);

                $text=dom::setAttribute("select", "com", "data", $text);
                $text=dom::setAttribute("select", "table", $selectTable, $text);
                $text=dom::setAttribute("option", "value", "[id]", $text);
                $text=dom::replaceInnerHtml("option", "[$selectTable]", $text);
                }


            // falls required_text, Fehlermeldung einbinden
            if ($dataForm->data['type'] == "required_text")
                {

//$text = dom::replaceInnerHtml("label", $dataForm->data['field']." [error:{$dataForm->data['field']}]",$text);
                $text=dom::replaceInnerHtml("label", $dataForm->data['field'] . ' <span com="error" field="'
                    . $dataForm->data['field'] . '" error_message="uups, es gab einen Fehler!!!">Error Message</span>',
                    $text);
                $text=dom::setAttribute("input", "check_content", "on", $text);
                $text=dom::setAttribute("input", "check_content_error_message", "uups, hier gabs einen fehler.", $text);
                }

            // falls required_email
            if ($dataForm->data['type'] == "required_email")
                {

//$text = dom::replaceInnerHtml("label", $dataForm->data['field']." [error:{$dataForm->data['field']}]",$text);
                $text=dom::replaceInnerHtml("label", $dataForm->data['field'] . ' <span com="error" field="'
                    . $dataForm->data['field']
                    . '" error_message="Keine gÃƒÂ¼ltige eMail Adresse.">Error Message</span>', $text);
                $text=dom::setAttribute("input", "check_email", "on", $text);
//$text=dom::setAttribute("input", "check_content_error_message", "uups, hier gabs einen fehler.", $text);
                }


            // Set Focus setzen
            if ($counter == 0)
                $text=dom::setAttribute("input", "setfocus", "on", $text);


            //echo $text;

            $html=$html . $text;

            $counter++;
            } while ($dataForm->nextRow());

        $text=component::getCom("input_submit");
        $html=$html . $text;

        $html=$html . "</form>";

        $dom=str_get_html($html);

        foreach ($dom->find('form') as $e)
            {
            // [header] --> zum EinfÃƒÂ¼gen von Header Informationen, die direkt aus dem File stammen
            //$e->innertext = $e->innertext.'<div com="content_header" field=""></div>[header]';
            $e->table = $this->table;
            $e->com_action="form_save";
            //$e->redirect  =$this->urlReport;
            $e->redirect=$this->formRedirect;
            }

        $html=$dom->save();
        $dom->clear();
        unset($dom);

        $this->htmlForm=$this->htmlForm . $html;

        //return $html;

        }


    /* function createTable()
         {
         $class   ="snapol_table";
 
         $dataForm=new data("_table_field, _table, _table_field_type", "`table`='$this->table'", "item_order");
         $dataForm=new data("_table_field, _table, _table_field_type", "`table`='$this->table'", "item_order");
 
         $header  ="";
         $body    ="";
 
         do
             {
             if (in_array(strtolower($dataForm->data['field']), $this->tableField))
                 {
                 $headerField="";
                 $bodyField  ="";
 
                 
                 // falls Text
                  if (($dataForm->data['type'] == "text") or ($dataForm->data['type'] == "required_text"))
                     {
                        $headerField="{$dataForm->data['field']}";
                        $bodyField  ="[{$dataForm->data['field']}]";    
                     }
                 
                 
                 // falls eMail
                  if (($dataForm->data['type'] == "email") or ($dataForm->data['type'] == "required_email"))
                     {
                        $headerField="{$dataForm->data['field']}";
                 $bodyField  ='<a href="mailto:['.$dataForm->data['field'].']">['.$dataForm->data['field'].']</a>';  
                         
                         
                         
                     }
                 
                 
                 
 
                 // falls Image
                 $imageField = $dataForm->data['field'];
                 $imageSize = 5000;
                 
                 
                 if ($dataForm->data['type'] == "image")    //or ($dataForm->data['type'] == "resize_image"))
                     {
                     $headerField="&nbsp;";
                     
                     // ist ein resize feld vorhanden
                     
                     for ($n=0; $n < sizeof($this->tableField); $n++) {
                         
                         $tmp = explode("_", $this->tableField[$n]);
                         
                         if (sizeof($tmp) == 2) {
                             
                             if (strtolower($tmp[0]) == strtolower($dataForm->data['field'])) {
                                 
                             // ist das bild kleiner
                             if ($tmp[1] < $imageSize) {
                              $imageField = $this->tableField[$n];
                              $imageSize = $tmp[1];
                             }
                             
                             }
                             
                             
                             
                             
                         }
                         
                         
                     }
                     
                     
                     
                     
                     $bodyField  ='<img src="[' . $imageField . ']" border="0" />';
                     }
 
                     
                     
                 
                 
                if ($headerField !== "") { 
                 $header=$header . "<th>$headerField</th>";
                                 $body  =$body . "<td>$bodyField</td>";
                }
                 
                 
                 
                 }
             } while ($dataForm->nextRow());
 
         $header=$header . "<th>&nbsp;</th>";
         $body  =$body . "<td>" . $this->addDetailView() . "</td>";
 
         $header=$header . "<th>&nbsp;</th>";
         $body  =$body . "<td>" . $this->addDetele() . "</td>";
 
         $html  ='<table class="' . $class . '"><thead><tr>' . $header . '</tr></thead><tbody><tr>' . $body
             . '</tr></tbody></table>';
 
         $dom   =str_get_html($html);
 
         foreach ($dom->find('tbody')as $e)
             {
             // [header] --> zum EinfÃƒÂ¼gen von Header Informationen, die direkt aus dem File stammen
             //$e->innertext = $e->innertext.'<div com="content_header" field=""></div>[header]';
             $e->com  = "data";
             $e->table=$this->table;
             $e->orderby = $this->tableOrderby;
             }
 
         $html=$dom->save();
         $dom->clear();
         unset($dom);
 
         $this->htmlReport=$this->htmlReport . $html;
 
         return $html;
         }  */


    /////////////////////////////////////////////////7


    // mÃƒÂ¼sste createHtmlTable heissen
    function createTable() //$table, $field, $editItem = false, $deleteItem = false, $editUrl = "", $search = false)
        {
        $this->tableArray=general::stringToArray($this->table);

        //$class           ="snapol_table";

        $headerField="";
        $bodyField="";

        $header="";
        $body="";

        $joinTable="";


        /*if ($this->tableField == "")
            {
            $field=db::getSnapolTableFieldArray($this->table);
            }
        else
            {
            $field=general::stringToArray($tableField);
            }*/


        //$fieldTitle = general::stringToArray($this->tableFieldTitle);

        $n=0;

        //print_r($this->tableField);

        //foreach ($field as $value)
        foreach ($this->tableField as $field)
            {
            //$type       = db::getSnapolTableFieldType($this->table, $value);
            //$type = "text";
            //$title      =db::getSnapolTableFieldName($this->table, $value);

            $type = $this->tableFieldType[$field];
            //$title=$value;


            //$headerField=$value;  //$fieldTitle[$n];
            $headerField=$field;
            $bodyField="[" . $field . "]";

            /*if ($type == "image")
                {
                $headerField="";
                $bodyField="";
                }*/

            if ($type == "image")
                {
                $headerField="&nbsp;";
                $bodyField='<img src="[' . $field . ':100]" />';
                }

            if ($type == "file")
                {
                //$headerField="&nbsp;";
                $bodyField='<a href="[' . $field . ']" target="_blank">[' . $field . ']</a>';
                }

            if ($type == "email")
                {
                $bodyField='<a href="mailto:[' . $field . ']">[' . $field . ']</a>';
                }

            if ($type == "url")
                {
                $bodyField='<a href="[' . $field . ']" target="_blank">[' . $field . ']</a>';
                }

            if ($type == "join")
                {
                //$joinTable=substr($field, 1);
                //$joinField=db::getSnapolTableFieldName($joinTable, $joinTable);

                //$headerField=$joinTable;
                $headerField=$field;

                //$bodyField="[" . $joinTable . "]";

                $optionField="";
                //if ($this->joinField !== "") {

                foreach (general::stringToArray($this->joinField[$field]) as $joinFieldItem)
                    {
                    $optionField=$optionField . "[$joinFieldItem] ";
                    //echo "item=$joinFieldItem***";
                    }


                // falls nichts definiert wurde
                if ($optionField === "")
                    {
                    $optionField="[" . substr($field, 1) . "]";
                    }

                $joinTable="$joinTable," . substr($field, 1);
                $bodyField=$optionField;
                }


            //$header = $header . "<th>$value</th>";
            if ($headerField !== "")
                {
                $header=$header . "<th>$headerField</th>";
                $body=$body . "<td>$bodyField</td>";
                }

            $n++;

            //$headerField="{".$value."}";
            //$bodyField  ="[$value]";

            }

        if ($this->editItem)
            {
            $header=$header . "<th>&nbsp;</th>";
            //$body  =$body . "<td>" . $this->addDetailView() . "</td>";
            $body=$body . '<td><a href="[system.base_url]' . $this->formUrl . '?id=[' . $this->tableArray[0]
                . '_id]">editieren</a></td>';
            }

        if ($this->deleteItem)
            {
            $header=$header . "<th>&nbsp;</th>";
            //$body  =$body . "<td>" . $this->addDetele() . "</td>";
            $body=$body . '<td><a href="" com="delete_data" table="' . $this->table . '" id="[' . $this->tableArray[0]
                . '_id]">löschen</a></td>';
            }

        $searchProperty="";

        if ($this->searchForm)
            {
            $searchProperty="[get:q]";
            }

        $html=
            '<table class="' . $this->tableClass . '"><thead><tr>' . $header . '</tr></thead><tbody com="data" table="'
            . $this->table . $joinTable . '" where="" orderby="' . $this->tableOrderby . '" search="' . $searchProperty
            . '"><tr>' . $body . '</tr></tbody></table>';

        /*$dom=str_get_html($html);


        //  foreach ($dom->find('tbody')as $e)
        foreach ($dom->find('tbody') as $e)
            {
            // dies funktioniert nicht, andere tags gehen, nur tbody nicht

            echo "found TBODY";

            // [header] --> zum EinfÃƒÂ¼gen von Header Informationen, die direkt aus dem File stammen
            //$e->innertext = $e->innertext.'<div com="content_header" field=""></div>[header]';
            $e->com="data";
            $e->table=$this->table . $joinTable;
            $e->orderby=$this->tableOrderby;

            if ($this->categoryTable !== "")
                {
                $e->where="_" . $this->categoryTable . "=[data_detail:id]";
                }

            if ($this->search)
                {
                $e->search="true";
                }
            }

        $html=$dom->save();
        $dom->clear();
        unset($dom); */


        // anzeigen
        if ($this->searchForm)
            {

            $html='<form id="form1" name="form1" method="get" action="">
  <label for="q"></label>
  <input type="text" name="q" id="q" value="[get:q]" />
  <input type="submit" name="button" id="button" value="Search" />
</form>'
                . $html;
            }

        if ($this->newItem)
            {
            $html='<p><a class="snapol_button" href="[system.base_url]' . $this->formUrl . '">Neuer Eintrag</a></p>' . $html;
            }

        $this->htmlReport=$this->htmlReport . $html;

        return $html;
        }

    function createCategory()
        {
        $html="";

        if ($this->categoryTable !== "")
            {
            $html=component::getCom("ul");

            $html=dom::setAttribute("ul", "com", "data", $html);
            $html=dom::setAttribute("ul", "table", $this->categoryTable, $html);
            $html=dom::replaceInnerHtml("li", '<a href="?table=' . $this->categoryTable . '&id2=[id2]">[usergroup]</a>',
                $html);
            }

        return $html;
        }

    function createList()
        {
        $html="";
        $joinTable="";

        $html=component::getCom("ul");


//$html = dom::replaceInnerHtml("li", '<a href="?table='.$this->categoryTable.'&id2=[id2]">[usergroup]</a>', $html);

        if ($this->tableField == "")
            {
            $field=db::getSnapolTableFieldArray($this->table);
            }
        else
            {
            $field=general::stringToArray($tableField);
            }

        //print_r($field);
        //$fieldTitle = general::stringToArray($this->tableFieldTitle);

        $n=0;

        $li="";

        foreach ($field as $value)
            {
            $type = db::getSnapolTableFieldType($this->table, $value);
            $title=db::getSnapolTableFieldName($this->table, $value);


            //$headerField=$value;  //$fieldTitle[$n];

            $bodyField="[" . $value . "]";

            if ($type == "image")
                {
                $headerField="";
                $bodyField="";
                }

            if ($type == "resize_image")
                {
                $bodyField='<img src="[' . $value . ']" />';
                }

            if (($type == "email") or ($type == "required_email"))
                {
                //$headerField="&nbsp;";
                $bodyField='<a href="mailto:[' . $value . ']">[' . $value . ']</a>';
                }

            if ($type == "url")
                {
                //$headerField="&nbsp;";
                $bodyField='<a href="[' . $value . ']">[' . $value . ']</a>';
                }

            if ($type == "join")
                {
                $joinTable=substr($value, 1);
                $joinField=db::getSnapolTableFieldName($joinTable, $joinTable);

                $headerField=$joinField;
                $bodyField="[" . $joinTable . "]";

                $joinTable=",$joinTable";
                }


            //$header = $header . "<th>$value</th>";
            if ($bodyField !== "")
                {
                //$header = $header . "<th>$headerField</th>";
                //$body  =$body . "<td>$bodyField</td>";
                $li=$li . $bodyField;
                }

            $n++;

            //$headerField="{".$value."}";
            //$bodyField  ="[$value]";

            }

        $li="<li>$li</li>";

        $html=dom::replaceInnerHtml("ul", $li, $html);
        $html=dom::setAttribute("ul", "com", "data", $html);
        $html=dom::setAttribute("ul", "table", $this->table . $joinTable, $html);
        return $html;
        }

    function addNewItem($url)
        {
        //$html=component::getCom("url_redirect");
        $html='<p><a class="snapol_button" href="' . $url . '">Neuer Eintrag</a></p>';

        //$html=dom::setAttribute("a", "redirect", $url, $html);
        //$html=dom::setAttribute("a", "class", "snapol_button", $html);
        //$html=dom::replaceInnerHtml("a", "Neuer Eintrag", $html);


        //<p><a href="" com_href="url_redirect" redirect="" parameter="">Url Redirect</a></p>
        // $this->htmlReport=$this->htmlReport . $html;

        return $html;
        }

    function addDetailView()
        {

        //  $text = component::getCom("data_detail_view");
        $html='<a href="data_detail_view" redirect="' . $this->formUrl . '" table="' . $this->tableArray[0]
            . '" id2="">editieren</a>';

        $html=dom::setAttribute("a", "redirect", $this->formUrl, $html);
        $html=dom::setAttribute("a", "table", $this->tableArray[0], $html);
        $html=dom::setAttribute("a", "id2", "[{$this->tableArray[0]}_id2]", $html);

        return $html;
        }


    //static function addDeleteButton($html) {}

    function addDetele()
        {

        //  $text = component::getCom("data_detail_view");
        $html='<a href="delete_data" table="" id2="">lÃƒÂ¶schen</a>';

        //$html = dom::setAttribute("a", "url", $url, $html);
        $html=dom::setAttribute("a", "table", $this->tableArray[0], $html);
        $html=dom::setAttribute("a", "id2", "[{$this->tableArray[0]}_id2]", $html);

        return $html;
        }
    }
?>